﻿using BBICMS.Model;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using BBICMS.Model.Works;

namespace BBICMS.Repository.Configuration
{
    public class WorkTypeConfiguration : EntityTypeConfiguration<WorkType>
    {
        public WorkTypeConfiguration()
        {
            this.HasKey(b => b.Id);
            this.Property(b => b.Id)
                .HasColumnName("Id")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            this.ToTable("Types");

            this.Property(p => p.Title).HasMaxLength(50).IsRequired();
            this.Property(p => p.Importance).IsRequired();
            this.Property(p => p.Active).IsRequired();
            this.Property(p => p.AddedDate).IsRequired().HasColumnType("datetime");
            this.Property(p => p.AddedBy).HasMaxLength(50);
            this.Property(p => p.UpdatedDate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.UpdatedBy).IsOptional().HasMaxLength(50);

            this.HasMany(a => a.Works).WithMany(b => b.WorkTypes).Map(m =>
            {
                m.MapLeftKey("TypeId");
                m.MapRightKey("WorkId");
                m.ToTable("Work_Types");
            });
        }
    }
}
